package com.weetop.cfw.home_page.activity

import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.IntentUtils
import com.coorchice.library.SuperTextView
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout
import com.luck.picture.lib.config.PictureSelectionConfig.listener
import com.weetop.cfw.R
import com.weetop.cfw.base.presenter.imp.WorkshopWarehouseListPresenterImp
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.ui.fragment.CommonBaseFragment
import com.weetop.cfw.base.view.WorkshopWarehouseListView
import com.weetop.cfw.bean.GeneralCodeTableBean
import com.weetop.cfw.bean.KindBean
import com.weetop.cfw.bean.SiteBean
import com.weetop.cfw.callback.AppBarLayoutStateChangeListener
import com.weetop.cfw.constants.Constants
import com.weetop.cfw.event.*
import com.weetop.cfw.home_page.fragment.WorkshopWarehouseListFragment
import com.weetop.cfw.utils.EventBusUtils
import com.weetop.cfw.utils.LogInUtils
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout
import kotlinx.android.synthetic.main.activity_workshop_warehouse_list.*

/**
 * 厂房仓库列表界面
 */
class WorkshopWarehouseListActivity : CommonBaseActivity(), View.OnClickListener,
    WorkshopWarehouseListView {
    override fun getPriceUnitSuccess(priceUnit: String?) {
        if (priceUnit != null) {
            if(priceUnit.contains("年")){
                punit=2300
            }else if(priceUnit.contains("月")){
                punit=2200
            }else  punit=2100
        }
    }

    override fun onClick(p0: View?) {
        when (p0?.id) {
            R.id.imageWorkshopWarehouseListBack -> ActivityUtils.finishActivity(this)
            R.id.linearIndustry -> {
                if (industryFilterPopupWindow.isShowing) {
                    industryFilterPopupWindow.dismiss()
                } else {

                    industryFilterPopupWindow.showAsDropDown(linearFilterWorkshop)
                    imageVagueBg.visibility = View.VISIBLE
                    priceFilterPopupWindow.dismiss()
                    areaFilterPopupWindow.dismiss()
                    mianJiFilterPopupWindow.dismiss()
                    sourceFilterPopupWindow.dismiss()

                    textIndustry.setTextColor(ColorUtils.getColor(R.color.c_1381CC))
                    imageIndustry.setImageResource(R.mipmap.arrow_down_blue_small)
                }
            }
            R.id.linearPrice -> {
                /*if(priceFilterPopupWindow.isShowing){
                    priceFilterPopupWindow.dismiss()
                }else{

                    priceFilterPopupWindow.showAsDropDown(linearFilterWorkshop)
                    imageVagueBg.visibility = View.VISIBLE
                    areaFilterPopupWindow.dismiss()
                    mianJiFilterPopupWindow.dismiss()
                    industryFilterPopupWindow.dismiss()
                    sourceFilterPopupWindow.dismiss()

                    textPrice.setTextColor(ColorUtils.getColor(R.color.c_1381CC))
                    imagePrice.setImageResource(R.mipmap.arrow_down_blue_small)
                }*/
                workshopWarehouseListPresenterImp.getPriceData(this, punit)
            }
            R.id.linearArea -> {
                if (!areaFilterPopupWindow.isShowing) {

                    areaFilterPopupWindow.showAsDropDown(linearFilterWorkshop)
                    imageVagueBg.visibility = View.VISIBLE
                    priceFilterPopupWindow.dismiss()
                    industryFilterPopupWindow.dismiss()
                    mianJiFilterPopupWindow.dismiss()
                    sourceFilterPopupWindow.dismiss()

                    textArea.setTextColor(ColorUtils.getColor(R.color.c_1381CC))
                    imageArea.setImageResource(R.mipmap.arrow_down_blue_small)
                } else {
                    areaFilterPopupWindow.dismiss()
                }
            }
            R.id.linearMianJi -> {
                if (!mianJiFilterPopupWindow.isShowing) {

                    mianJiFilterPopupWindow.showAsDropDown(linearFilterWorkshop)
                    imageVagueBg.visibility = View.VISIBLE
                    priceFilterPopupWindow.dismiss()
                    industryFilterPopupWindow.dismiss()
                    areaFilterPopupWindow.dismiss()
                    sourceFilterPopupWindow.dismiss()

                    textMianJi.setTextColor(ColorUtils.getColor(R.color.c_1381CC))
                    imageMianJi.setImageResource(R.mipmap.arrow_down_blue_small)
                } else {
                    mianJiFilterPopupWindow.dismiss()
                }
            }
            R.id.linearSource -> {
                if (sourceFilterPopupWindow.isShowing) {
                    sourceFilterPopupWindow.dismiss()
                } else {

                    sourceFilterPopupWindow.showAsDropDown(linearFilterWorkshop)
                    imageVagueBg.visibility = View.VISIBLE
                    priceFilterPopupWindow.dismiss()
                    industryFilterPopupWindow.dismiss()
                    areaFilterPopupWindow.dismiss()
                    mianJiFilterPopupWindow.dismiss()

                    textSource.setTextColor(ColorUtils.getColor(R.color.c_1381CC))
                    imageSource.setImageResource(R.mipmap.arrow_down_blue_small)
                }
            }
            R.id.relativeSearch -> SearchActivity.startSearchActivity(
                this@WorkshopWarehouseListActivity,
                1,
                workShopKindIndicator.selectedTabPosition
            )
            R.id.imagePublish -> {
                when (workShopKindIndicator.selectedTabPosition) {
                    0 -> {
                        if (LogInUtils.userIsLogIn()) {
                            PublishActivity.startPublishActivity(
                                this,
                                isEditPublishInfo = false,
                                isWorkshopOrWareHouse = true
                            )
                        }
                    }
                    1 -> {
                        if (LogInUtils.userIsLogIn()) {
                            PlantSalePublishActivity.startPlantSalePublishActivity(
                                this,
                                editPublish = false,
                                isWorkShopOrWarehouse = true
                            )
                        }
                    }
                    2 -> {
                        if (LogInUtils.userIsLogIn()) {
                            PublishActivity.startPublishActivity(
                                this,
                                isEditPublishInfo = false,
                                isWorkshopOrWareHouse = false
                            )
                        }
                    }
                    else -> {
                        if (LogInUtils.userIsLogIn()) {
                            PlantSalePublishActivity.startPlantSalePublishActivity(
                                this,
                                editPublish = false,
                                isWorkShopOrWarehouse = false
                            )
                        }
                    }
                }
            }
            R.id.imageCustomerServiceTelephoneNumbers -> ActivityUtils.startActivity(
                IntentUtils.getDialIntent(
                    Constants.CUSTOMER_SERVICE_PHONE_NUMBER
                )
            )
        }
    }

    private val titleList = listOf<String>(
        "厂房土地出租", "厂房土地出售", "仓库出租", "仓库出售"
    )

    private lateinit var workshopWarehouseListPresenterImp: WorkshopWarehouseListPresenterImp

    private lateinit var areaFilterPopupWindow: PopupWindow//区域
    private lateinit var mianJiFilterPopupWindow: PopupWindow//面积
    private lateinit var priceFilterPopupWindow: PopupWindow//价格
    private lateinit var industryFilterPopupWindow: PopupWindow//行业
    private lateinit var sourceFilterPopupWindow: PopupWindow//来源

    private lateinit var filterTagFlowLayout1: TagFlowLayout
    private lateinit var filterTagFlowLayout2: TagFlowLayout
    private lateinit var filterTagFlowLayout3: TagFlowLayout
    private lateinit var filterTagFlowLayout4: TagFlowLayout
    private lateinit var filterTagFlowLayout5: TagFlowLayout

    private lateinit var filterPopupWindowView1: View
    private lateinit var filterPopupWindowView2: View
    private lateinit var filterPopupWindowView3: View
    private lateinit var filterPopupWindowView4: View
    private lateinit var filterPopupWindowView5: View

    private lateinit var workshopWarehouseListPagerAdapter: WorkshopWarehouseListPagerAdapter

    private val firstWorkshopWarehouseKindFragment = WorkshopWarehouseListFragment.getInstance(0)
    private val secondWorkshopWarehouseKindFragment = WorkshopWarehouseListFragment.getInstance(1)
    private val thirdWorkshopWarehouseKindFragment = WorkshopWarehouseListFragment.getInstance(2)
    private val fourthWorkshopWarehouseKindFragment = WorkshopWarehouseListFragment.getInstance(3)

    private val workshopWarehouseKindFragmentList = listOf(
        firstWorkshopWarehouseKindFragment,
        secondWorkshopWarehouseKindFragment,
        thirdWorkshopWarehouseKindFragment,
        fourthWorkshopWarehouseKindFragment
    )

    private var punit = 2200

    override fun getLayoutId() = R.layout.activity_workshop_warehouse_list


    override fun initView(savedInstanceState: Bundle?) {
        workshopWarehouseListPresenterImp = WorkshopWarehouseListPresenterImp()
        workshopWarehouseListPresenterImp.attachView(this)

        setViewsOnClickListener(
            this,
            linearArea,
            linearPrice,
            linearSource,
            linearMianJi,
            relativeSearch,
            linearIndustry,
            imageWorkshopWarehouseListBack,
            imagePublish,
            imageCustomerServiceTelephoneNumbers
        )

        filterPopupWindowView1 =
            View.inflate(context, R.layout.layout_filter_popup_window_layout, null)
        filterPopupWindowView2 =
            View.inflate(context, R.layout.layout_filter_popup_window_layout, null)
        filterPopupWindowView3 =
            View.inflate(context, R.layout.layout_filter_popup_window_layout, null)
        filterPopupWindowView4 =
            View.inflate(context, R.layout.layout_filter_popup_window_layout, null)
        filterPopupWindowView5 =
            View.inflate(context, R.layout.layout_filter_popup_window_layout, null)
        filterTagFlowLayout1 = filterPopupWindowView1.findViewById(R.id.filterTagFlowLayout)
        filterTagFlowLayout2 = filterPopupWindowView2.findViewById(R.id.filterTagFlowLayout)
        filterTagFlowLayout3 = filterPopupWindowView3.findViewById(R.id.filterTagFlowLayout)
        filterTagFlowLayout4 = filterPopupWindowView4.findViewById(R.id.filterTagFlowLayout)
        filterTagFlowLayout5 = filterPopupWindowView5.findViewById(R.id.filterTagFlowLayout)

        initAreaFilterPopupWindow()
        initIndustryFilterPopupWindow()
        initMianJiFilterPopupWindow()
        initPriceFilterPopupWindow()
        initSourceFilterPopupWindow()

        priceFilterPopupWindow.setOnDismissListener {
            textPrice.setTextColor(ColorUtils.getColor(android.R.color.black))
            if (!areaFilterPopupWindow.isShowing && !industryFilterPopupWindow.isShowing && !mianJiFilterPopupWindow.isShowing && !sourceFilterPopupWindow.isShowing) {
                imageVagueBg.visibility = View.INVISIBLE
            }
            imagePrice.setImageResource(R.mipmap.arrow_down_black_small)
        }
        industryFilterPopupWindow.setOnDismissListener {
            textIndustry.setTextColor(ColorUtils.getColor(android.R.color.black))
            if (!areaFilterPopupWindow.isShowing && !mianJiFilterPopupWindow.isShowing && !priceFilterPopupWindow.isShowing && !sourceFilterPopupWindow.isShowing) {
                imageVagueBg.visibility = View.INVISIBLE
            }
            imageIndustry.setImageResource(R.mipmap.arrow_down_black_small)
        }
        areaFilterPopupWindow.setOnDismissListener {
            textArea.setTextColor(ColorUtils.getColor(android.R.color.black))
            if (!industryFilterPopupWindow.isShowing && !priceFilterPopupWindow.isShowing && !mianJiFilterPopupWindow.isShowing && !sourceFilterPopupWindow.isShowing) {
                imageVagueBg.visibility = View.INVISIBLE
            }
            imageArea.setImageResource(R.mipmap.arrow_down_black_small)
        }
        mianJiFilterPopupWindow.setOnDismissListener {
            textMianJi.setTextColor(ColorUtils.getColor(android.R.color.black))
            if (!industryFilterPopupWindow.isShowing && !priceFilterPopupWindow.isShowing && !areaFilterPopupWindow.isShowing && !sourceFilterPopupWindow.isShowing) {
                imageVagueBg.visibility = View.INVISIBLE
            }
            imageMianJi.setImageResource(R.mipmap.arrow_down_black_small)
        }
        sourceFilterPopupWindow.setOnDismissListener {
            textSource.setTextColor(ColorUtils.getColor(android.R.color.black))
            if (!industryFilterPopupWindow.isShowing && !priceFilterPopupWindow.isShowing && !areaFilterPopupWindow.isShowing && !mianJiFilterPopupWindow.isShowing) {
                imageVagueBg.visibility = View.INVISIBLE
            }
            imageSource.setImageResource(R.mipmap.arrow_down_black_small)
        }

        appBarLayout.addOnOffsetChangedListener(object : AppBarLayoutStateChangeListener() {
            override fun onOffsetChanged(appBarLayout: AppBarLayout?) {
                dismissFilterPopupWindow()
            }
        })
    }

    /**
     * 隐藏显示的选择筛选条件的PopupWindow
     */
    private fun dismissFilterPopupWindow() {
        if (areaFilterPopupWindow.isShowing) {
            areaFilterPopupWindow.dismiss()
        }
        if (mianJiFilterPopupWindow.isShowing) {
            mianJiFilterPopupWindow.dismiss()
        }
        if (priceFilterPopupWindow.isShowing) {
            priceFilterPopupWindow.dismiss()
        }
        if (industryFilterPopupWindow.isShowing) {
            industryFilterPopupWindow.dismiss()
        }
        if (sourceFilterPopupWindow.isShowing) {
            sourceFilterPopupWindow.dismiss()
        }
    }

    override fun initData(savedInstanceState: Bundle?) {
        workshopWarehouseListPagerAdapter = WorkshopWarehouseListPagerAdapter(
            supportFragmentManager,
            workshopWarehouseKindFragmentList,
            titleList
        )
        workShopWareHouseListViewPager.offscreenPageLimit = 4
        workShopWareHouseListViewPager.adapter = workshopWarehouseListPagerAdapter

        initTabLayout()

        workshopWarehouseListPresenterImp.getQuYuData(this)
        workshopWarehouseListPresenterImp.getAreaData(this)
        workshopWarehouseListPresenterImp.getIndustryData(this)
        workshopWarehouseListPresenterImp.getSourceData(this)
        workshopWarehouseListPresenterImp.getPriceUnitBySiteId(
            WorkshopWarehouseListActivity(), Constants.siteId
        )
    }

    /**
     * 初始化价格筛选的PopupWindow
     */
    private fun initPriceFilterPopupWindow() {
        priceFilterPopupWindow = PopupWindow(context)
        priceFilterPopupWindow.contentView = filterPopupWindowView1
        priceFilterPopupWindow.isOutsideTouchable = true
        priceFilterPopupWindow.setBackgroundDrawable(
            ContextCompat.getDrawable(
                context,
                R.drawable.solid_white_shape
            )
        )
        priceFilterPopupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
        priceFilterPopupWindow.width = ViewGroup.LayoutParams.MATCH_PARENT
    }

    /**
     * 初始化来源筛选的PopupWindow
     */
    private fun initSourceFilterPopupWindow() {
        sourceFilterPopupWindow = PopupWindow(context)
        sourceFilterPopupWindow.contentView = filterPopupWindowView5
        sourceFilterPopupWindow.isOutsideTouchable = true
        sourceFilterPopupWindow.setBackgroundDrawable(
            ContextCompat.getDrawable(
                context,
                R.drawable.solid_white_shape
            )
        )
        sourceFilterPopupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
        sourceFilterPopupWindow.width = ViewGroup.LayoutParams.MATCH_PARENT
    }

    /**
     * 初始化行业筛选的PopupWindow
     */
    private fun initIndustryFilterPopupWindow() {
        industryFilterPopupWindow = PopupWindow(context)
        industryFilterPopupWindow.contentView = filterPopupWindowView2
        industryFilterPopupWindow.isOutsideTouchable = true
        industryFilterPopupWindow.setBackgroundDrawable(
            ContextCompat.getDrawable(
                context,
                R.drawable.solid_white_shape
            )
        )
        industryFilterPopupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
        industryFilterPopupWindow.width = ViewGroup.LayoutParams.MATCH_PARENT
    }

    /**
     * 初始化地区筛选的PopupWindow
     */
    private fun initAreaFilterPopupWindow() {
        areaFilterPopupWindow = PopupWindow(context)
        areaFilterPopupWindow.contentView = filterPopupWindowView3
        areaFilterPopupWindow.isOutsideTouchable = true
        areaFilterPopupWindow.setBackgroundDrawable(
            ContextCompat.getDrawable(
                context,
                R.drawable.solid_white_shape
            )
        )
        areaFilterPopupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
        areaFilterPopupWindow.width = ViewGroup.LayoutParams.MATCH_PARENT
    }

    /**
     * 初始化面积筛选的PopupWindow
     */
    private fun initMianJiFilterPopupWindow() {
        mianJiFilterPopupWindow = PopupWindow(context)
        mianJiFilterPopupWindow.contentView = filterPopupWindowView4
        mianJiFilterPopupWindow.isOutsideTouchable = true
        mianJiFilterPopupWindow.setBackgroundDrawable(
            ContextCompat.getDrawable(
                context,
                R.drawable.solid_white_shape
            )
        )
        mianJiFilterPopupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
        mianJiFilterPopupWindow.width = ViewGroup.LayoutParams.MATCH_PARENT
    }

    private fun initTabLayout() {
        workShopKindIndicator.addTab(workShopKindIndicator.newTab().setText(titleList[0]).setIcon(R.mipmap.ic_launcher))
        workShopKindIndicator.addTab(workShopKindIndicator.newTab().setText(titleList[1]).setIcon(R.mipmap.ic_launcher))
        workShopKindIndicator.addTab(workShopKindIndicator.newTab().setText(titleList[2]).setIcon(R.mipmap.ic_launcher))
        workShopKindIndicator.addTab(workShopKindIndicator.newTab().setText(titleList[3]).setIcon(R.mipmap.ic_launcher))

        workShopKindIndicator.setupWithViewPager(workShopWareHouseListViewPager)
        workShopKindIndicator.getTabAt(0)?.setText(titleList[0])
            ?.setIcon(R.mipmap.plant_land_lease_logo)
        workShopKindIndicator.getTabAt(1)?.setText(titleList[1])
            ?.setIcon(R.mipmap.sale_of_plant_land_logo)
        workShopKindIndicator.getTabAt(2)?.setText(titleList[2])
            ?.setIcon(R.mipmap.warehouse_rental_logo_other)
        workShopKindIndicator.getTabAt(3)?.setText(titleList[3])
            ?.setIcon(R.mipmap.warehouse_sale_logo_other)
        workShopKindIndicator.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab?) {
                if (tab != null) {
                    if (tab.position == 0 || tab.position == 2) {
                        workshopWarehouseListPresenterImp.getPriceUnitBySiteId(
                            WorkshopWarehouseListActivity(), Constants.siteId
                        )
                    } else {
                        punit = 1600
                    }
                }
            }
            override fun onTabReselected(p0: TabLayout.Tab?) {
            }
            override fun onTabUnselected(p0: TabLayout.Tab?) {
            }
        })
    }

    private class WorkshopWarehouseListPagerAdapter(
        fragmentManager: FragmentManager,
        var leaseSaleInformationFragmentList: List<CommonBaseFragment>,
        var titleList: List<String>
    ) : FragmentStatePagerAdapter(fragmentManager) {

        override fun getItem(position: Int) = leaseSaleInformationFragmentList[position]

        override fun getCount() = leaseSaleInformationFragmentList.size

        override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
//            super.destroyItem(container, position, `object`)
        }

        override fun restoreState(state: Parcelable?, loader: ClassLoader?) {
//            super.restoreState(state, loader)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        Constants.workshopAreaId = 0
        Constants.workshopIntId = 0
        workshopWarehouseListPresenterImp.detachView()
    }

    /**
     * 种类数据获取成功
     */
    override fun kindDataGetSuccess(kindBean: KindBean?) {
        if (kindBean != null) {
            val kindDataList = kindBean.data
            filterTagFlowLayout2.adapter = object : TagAdapter<KindBean.DataBean>(kindDataList) {
                override fun getView(
                    parent: FlowLayout?,
                    position: Int,
                    t: KindBean.DataBean?
                ): View {
                    val filterSearchResultFlowLayoutView = LayoutInflater.from(context)
                        .inflate(R.layout.layout_item_filter_tag_flow, parent, false)
                    val textFilterItem =
                        filterSearchResultFlowLayoutView.findViewById<SuperTextView>(R.id.textFilterItem)
                    textFilterItem.text = kindDataList[position].codename
                    return filterSearchResultFlowLayoutView
                }
            }
            filterTagFlowLayout2.setOnTagClickListener { view, position, parent ->
                EventBusUtils.postSticky(kindDataList[position])
                true
            }
        }
    }

    /**
     * 面积数据获取成功
     */
    override fun areaDataGetSuccess(generalCodeTableBean: GeneralCodeTableBean?) {
        if (generalCodeTableBean != null) {
            val areaDataList = generalCodeTableBean.data
            filterTagFlowLayout4.adapter =
                object : TagAdapter<GeneralCodeTableBean.DataBean>(areaDataList) {
                    override fun getView(
                        parent: FlowLayout?,
                        position: Int,
                        t: GeneralCodeTableBean.DataBean?
                    ): View {
                        val filterSearchResultFlowLayoutView = LayoutInflater.from(context)
                            .inflate(R.layout.layout_item_filter_tag_flow, parent, false)
                        val textFilterItem =
                            filterSearchResultFlowLayoutView.findViewById<SuperTextView>(R.id.textFilterItem)
                        textFilterItem.text = areaDataList[position].codename
                        return filterSearchResultFlowLayoutView
                    }

                    override fun onSelected(position: Int, view: View?) {
                        super.onSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(true, view)
                        val areaBean: GeneralCodeTableBean.DataBean = areaDataList[position]
                        val mianJiFilterEvent = MianJiFilterEvent(
                            areaBean,
                            workShopKindIndicator.selectedTabPosition,
                            false
                        )
                        EventBusUtils.postSticky(mianJiFilterEvent)
                        mianJiFilterPopupWindow.dismiss()
                    }

                    override fun unSelected(position: Int, view: View?) {
                        super.unSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(false, view)
                        val mianJiFilterEvent = MianJiFilterEvent(
                            areaDataList[position],
                            workShopKindIndicator.selectedTabPosition,
                            true
                        )
                        EventBusUtils.postSticky(mianJiFilterEvent)
                        mianJiFilterPopupWindow.dismiss()
                    }
                }
        }
    }

    /**
     * 区域数据获取成功
     */
    override fun quYuGetSuccess(siteBean: SiteBean?) {
        if (siteBean != null) {
            val siteDataBeanList = siteBean.data
            filterTagFlowLayout3.adapter =
                object : TagAdapter<SiteBean.DataBean>(siteDataBeanList) {
                    override fun getView(
                        parent: FlowLayout?,
                        position: Int,
                        t: SiteBean.DataBean?
                    ): View {
                        val filterSearchResultFlowLayoutView = LayoutInflater.from(context)
                            .inflate(R.layout.layout_item_filter_tag_flow, parent, false)
                        val textFilterItem =
                            filterSearchResultFlowLayoutView.findViewById<SuperTextView>(R.id.textFilterItem)
                        textFilterItem.text = siteDataBeanList[position].areaname
                        return filterSearchResultFlowLayoutView
                    }

                    override fun onSelected(position: Int, view: View?) {
                        super.onSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(true, view)
                        Constants.workshopAreaId = siteDataBeanList[position].areaid
                        val areaFilterEvent = AreaFilterEvent(
                            siteDataBeanList[position],
                            workShopKindIndicator.selectedTabPosition,
                            false
                        )
                        EventBusUtils.postSticky(areaFilterEvent)
                        areaFilterPopupWindow.dismiss()
                    }

                    override fun unSelected(position: Int, view: View?) {
                        super.unSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(false, view)
                        Constants.workshopAreaId = siteDataBeanList[position].areaid
                        val areaFilterEvent = AreaFilterEvent(
                            siteDataBeanList[position],
                            workShopKindIndicator.selectedTabPosition,
                            true
                        )
                        EventBusUtils.postSticky(areaFilterEvent)
                        areaFilterPopupWindow.dismiss()
                    }
                }
        }
    }

    /**
     * 价格筛选数据获取成功
     */
    override fun priceFilterDataGetSuccess(generalCodeTableBean: GeneralCodeTableBean?) {
        if (generalCodeTableBean != null) {
            val priceFilterDataList = generalCodeTableBean.data
            filterTagFlowLayout1.adapter =
                object : TagAdapter<GeneralCodeTableBean.DataBean>(priceFilterDataList) {
                    override fun getView(
                        parent: FlowLayout?,
                        position: Int,
                        t: GeneralCodeTableBean.DataBean?
                    ): View {
                        val filterSearchResultFlowLayoutView = LayoutInflater.from(context)
                            .inflate(R.layout.layout_item_filter_tag_flow, parent, false)
                        val textFilterItem =
                            filterSearchResultFlowLayoutView.findViewById<SuperTextView>(R.id.textFilterItem)
                        textFilterItem.text = priceFilterDataList[position].codename
                        return filterSearchResultFlowLayoutView
                    }

                    override fun onSelected(position: Int, view: View?) {
                        super.onSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(true, view)
                        val priceFilterEvent = PriceFilterEvent(
                            priceFilterDataList[position],
                            workShopKindIndicator.selectedTabPosition,
                            false
                        )
                        EventBusUtils.postSticky(priceFilterEvent)
                        priceFilterPopupWindow.dismiss()
                    }

                    override fun unSelected(position: Int, view: View?) {
                        super.unSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(false, view)
                        val priceFilterEvent = PriceFilterEvent(
                            priceFilterDataList[position],
                            workShopKindIndicator.selectedTabPosition,
                            true
                        )
                        EventBusUtils.postSticky(priceFilterEvent)
                        priceFilterPopupWindow.dismiss()
                    }

                }
            priceFilterPopupWindow.showAsDropDown(linearFilterWorkshop)
            imageVagueBg.visibility = View.VISIBLE
            areaFilterPopupWindow.dismiss()
            mianJiFilterPopupWindow.dismiss()
            industryFilterPopupWindow.dismiss()
            sourceFilterPopupWindow.dismiss()

            textPrice.setTextColor(ColorUtils.getColor(R.color.c_1381CC))
            imagePrice.setImageResource(R.mipmap.arrow_down_blue_small)
        }
    }

    /**
     * 切换选中状态和非选中状态
     */
    private fun selectedStateAndUnselectedStateSwitch(isSelected: Boolean, view: View?) {
        if (view != null) {
            val textFilterItem = view.findViewById<SuperTextView>(R.id.textFilterItem)
            if (isSelected) {
                textFilterItem.setTextColor(ColorUtils.getColor(android.R.color.white))
                textFilterItem.solid = ColorUtils.getColor(R.color.c_1381CC)
            } else {
                textFilterItem.setTextColor(ColorUtils.getColor(android.R.color.black))
                textFilterItem.solid = ColorUtils.getColor(R.color.F5F8FC)
            }
        }
    }

    /**
     * 行业数据获取成功
     */
    override fun industryFilterDataGetSuccess(generalCodeTableBean: GeneralCodeTableBean?) {
        if (generalCodeTableBean != null) {
            val industryFilterDataList = generalCodeTableBean.data
            filterTagFlowLayout2.adapter =
                object : TagAdapter<GeneralCodeTableBean.DataBean>(industryFilterDataList) {
                    override fun getView(
                        parent: FlowLayout?,
                        position: Int,
                        t: GeneralCodeTableBean.DataBean?
                    ): View {
                        val filterSearchResultFlowLayoutView = LayoutInflater.from(context)
                            .inflate(R.layout.layout_item_filter_tag_flow, parent, false)
                        val textFilterItem =
                            filterSearchResultFlowLayoutView.findViewById<SuperTextView>(R.id.textFilterItem)
                        textFilterItem.text = industryFilterDataList[position].codename
                        return filterSearchResultFlowLayoutView
                    }

                    override fun onSelected(position: Int, view: View?) {
                        super.onSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(true, view)
                        EventBusUtils.postSticky(
                            IndustryFilterEvent(
                                industryFilterDataList[position],
                                workShopKindIndicator.selectedTabPosition,
                                false
                            )
                        )
                        industryFilterPopupWindow.dismiss()
                    }

                    override fun unSelected(position: Int, view: View?) {
                        super.unSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(false, view)
                        EventBusUtils.postSticky(
                            IndustryFilterEvent(
                                industryFilterDataList[position],
                                workShopKindIndicator.selectedTabPosition,
                                true
                            )
                        )
                        industryFilterPopupWindow.dismiss()
                    }
                }
        }
    }

    /**
     * 来源数据获取成功
     */
    override fun sourceFilterDataGetSuccess(generalCodeTableBean: GeneralCodeTableBean?) {
        if (generalCodeTableBean != null) {
            val sourceFilterDataList = generalCodeTableBean.data
            filterTagFlowLayout5.adapter =
                object : TagAdapter<GeneralCodeTableBean.DataBean>(sourceFilterDataList) {
                    override fun getView(
                        parent: FlowLayout?,
                        position: Int,
                        t: GeneralCodeTableBean.DataBean?
                    ): View {
                        val filterSearchResultFlowLayoutView = LayoutInflater.from(context)
                            .inflate(R.layout.layout_item_filter_tag_flow, parent, false)
                        val textFilterItem =
                            filterSearchResultFlowLayoutView.findViewById<SuperTextView>(R.id.textFilterItem)
                        textFilterItem.text = sourceFilterDataList[position].codename
                        return filterSearchResultFlowLayoutView
                    }

                    override fun onSelected(position: Int, view: View?) {
                        super.onSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(true, view)
                        EventBusUtils.postSticky(
                            SourceFilterEvent(
                                sourceFilterDataList[position],
                                workShopKindIndicator.selectedTabPosition,
                                false
                            )
                        )
                        sourceFilterPopupWindow.dismiss()
                    }

                    override fun unSelected(position: Int, view: View?) {
                        super.unSelected(position, view)
                        selectedStateAndUnselectedStateSwitch(false, view)
                        EventBusUtils.postSticky(
                            SourceFilterEvent(
                                sourceFilterDataList[position],
                                workShopKindIndicator.selectedTabPosition,
                                true
                            )
                        )
                        sourceFilterPopupWindow.dismiss()
                    }
                }

        }
    }

}